package com.sgcc.fj.pmos.e_fj_home.presenter;

import com.alibaba.android.arouter.utils.TextUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.sgcc.fj.pmos.common.base.BasePresenter;
import com.sgcc.fj.pmos.common.http.HttpInterConst;
import com.sgcc.fj.pmos.common.http.HttpRequestUtils;
import com.sgcc.fj.pmos.common.http.MvpNetCallback;
import com.sgcc.fj.pmos.common.utils.ListPageUtil;
import com.sgcc.fj.pmos.common.utils.UserManager;

import com.sgcc.fj.pmos.e_fj_home.bean.InfomationMsgBean;
import com.sgcc.fj.pmos.e_fj_home.contract.InfomationMessageListContract;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;

public class InfomationMessageListPresenter extends BasePresenter<InfomationMessageListContract.View>
        implements InfomationMessageListContract.Presenter {


    @Override
    public void getMsg(String type, int pageNum, boolean isloading) {
        Map<String, Object> params = new HashMap<>();
        Map<String, Object> data = new HashMap<>();
        data.put("marketId", "PDBLN");
        String url = "";
        if ("zxxx".equals(type)) {
            data.put("title", "");
            url = HttpInterConst.INFORMATION_DISCLOSURE_GETLATEST;
        } else {
            url = HttpInterConst.INFORMATION_DISCLOSURE_GETHOT;
        }
        params.put("data", data);
        Map<String, Object> pageInfo = new HashMap<>();
        pageInfo.put("pageSize", 20);
        pageInfo.put("pageNum", new ListPageUtil(pageNum, ListPageUtil.pageSize2).getTotalPage());
        params.put("pageInfo", pageInfo);
        HttpRequestUtils.getInstance().request(params, url, new MvpNetCallback<InfomationMsgBean>(getView(), false) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                // 失败回调 判断界面是否销毁
                if (!isViewAttached()) {
                    return;
                }
                getView().getInfomationMsgListFailed();
            }

            @Override
            public void onResponse(InfomationMsgBean response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                if (response != null) {
                    if ("0".equals(response.getStatus())) {
                        getView().getInfomationMsgListSuccess(response);
                    } else {
                        if (!TextUtils.isEmpty(response.getMessage())) {
                            ToastUtils.showShort(response.getMessage());
                        }
                    }
                }
            }
        });
    }
}
